import {
  areaList
} from '@vant/area-data';
export const location = () => {
  let areaData = [ [], [], [] ]
  let areaSelect = [ [], [], [] ]
  for (let key in areaList.province_list) {
    areaData[0].push({
      name: areaList.province_list[key],
      code: key
    })
    areaSelect[0].push(areaList.province_list[key])
  }
  for (let key in areaList.city_list) {
    areaData[1].push({
      name: areaList.city_list[key],
      code: key
    })
    areaSelect[1].push(areaList.city_list[key])
  }
  for (let key in areaList.county_list) {
    areaData[2].push({
      name: areaList.county_list[key],
      code: key
    })
    areaSelect[2].push(areaList.county_list[key])
  }
  let areaListData = {
    areaData: areaData,
    areaSelect: areaSelect
  }
  return areaListData
}
export const locations = () => {
  let datas = []
  for (let key in areaList.province_list) {
    datas.push({
      areaName: areaList.province_list[key],
      childrenList: [],
      coding: Number(key),
      id: Number(key.slice(0, 2)),
      level: 1,
      parentId: (key == '410000' || key == '420000' || key == '430000') ? 8000000 : (key == '810000' || key == '820000') ? 7000000 : Number(key.slice(0, 1) + '000000')
    })

  }
  datas.map((item) => {
    for (let key in areaList.city_list) {
      if (key.slice(0, 2) == item.id) {
        item.childrenList.push({
          areaName: areaList.city_list[key],
          childrenList: [],
          coding: Number(key),
          id: Number(key.slice(0, 4)),
          level: 2,
          parentId: item.coding
        })
      }


    }
  })
  datas.map((item) => {
    item.childrenList && item.childrenList.length > 0 && item.childrenList.map((child) => {
      for (let key in areaList.county_list) {
        if (child.id == key.slice(0, 4)) {
          child.childrenList.push({
            areaName: areaList.county_list[key],
            childrenList: [],
            coding: Number(key),
            id: Number(key),
            level: 3,
            parentId: child.coding
          })
        }
      }
    })
  })
  return datas
}
export const areaData = locations()
export const areaListData = location()